package com.adcc.monitoragent.log;

import com.adcc.monitoragent.bean.ServiceLogBean;
import com.adcc.monitoragent.send.MessageSend;

public class ServiceLogger {
	private static String ip;//服务器ip
	private static String port;//服务使用的端口
	private static String serviceName;//服务名
	/**
	 * 使用日志前要进行全局初始化
	 * @param ip
	 * @param port
	 * @param serviceName
	 */
	public static void init(String ip, String port, String serviceName) {
		ServiceLogger.ip = ip;
		ServiceLogger.port = port;
		ServiceLogger.serviceName = serviceName;
	}

	public static String getIp() {
		return ip;
	}

	public static String getPort() {
		return port;
	}

	public static String getServiceName() {
		return serviceName;
	}
	/**
	 * 普通日志
	 * @param msg
	 */
	public static void info(String msg) {
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.INFO,
				msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
	/**
	 * 普通日志
	 * @param ip
	 * @param port
	 * @param serviceName
	 * @param msg
	 */
	public static void info(String ip, String port, String serviceName, String msg) {
		//ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.INFO,"["+ ServiceLogger.serviceName + ServiceLogger.ip + "]" + msg, ip, port, serviceName);
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.INFO, msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
	/**
	 * 告警日志
	 * @param msg
	 */
	public static void warn(String msg) {
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.WARN,
				msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
	/**
	 * 告警日志
	 * @param ip
	 * @param port
	 * @param serviceName
	 * @param msg
	 */
	public static void warn(String ip, String port, String serviceName, String msg) {
		//ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.WARN,"["+ ServiceLogger.serviceName + ServiceLogger.ip + "]" + msg, ip, port, serviceName);
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.WARN, msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
	/**
	 * 日常日志
	 * @param msg
	 */
	public static void error(String msg) {
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.ERROR,
				msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
	/**
	 * 异常日志
	 * @param ip
	 * @param port
	 * @param serviceName
	 * @param msg
	 */
	public static void error(String ip, String port, String serviceName, String msg) {
		//ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.ERROR,"["+ ServiceLogger.serviceName + ServiceLogger.ip + "]" + msg, ip, port, serviceName);
		ServiceLogBean logBean = new ServiceLogBean(ServiceLogBean.ERROR, msg, ip, port, serviceName);
		//转发消息
		MessageSend.sendMsg(logBean);
	}
}
